<?php
// +----------------------------------------------------------------------
// | Qbt CMS Plugin
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2018 http://www.qbt8.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 黄老邪 <develop02@qbt8.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_app_update\controller;
use cmf\controller\PluginAdminBaseController;
use plugins\qbt_app_update\controller\ApkarserController;
use think\Db;

class IndexController
{

    public function _initialize()
    {

    }
    //当前设备识别
    public function data_url(){
        $id = intval(input('id'));
        if(!$id){$id = 2;}
        if($id) {
            $info = Db::name('app_update')->where('id =' . $id)->find();
            if ($info) {

                $apk_url = cmf_get_file_download_url($info['apk_url']);
                if($info['type'] == 2){//ios
                    $apk_url = $info['apk_url'];
                }

                $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
                $iphone = (strpos($agent, 'iphone')) ? true : false;
                $ipad = (strpos($agent, 'ipad')) ? true : false;
                $android = (strpos($agent, 'android')) ? true : false;
                $weixin = strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') ? true : false;

                $windows = (strpos($agent, 'windows ')) ? true : false;

                if ($weixin ) {
                    echo "<script> alert('点击右上角，浏览器中打开');</script>";exit;

                } if ($iphone || $ipad || $android) {

                    echo "<script>window.location.href='$apk_url'</script>";//这里也可以是网址

                }
            }
        }
        return '操作有误，请稍后再试';

    }


}
